<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ text.ID ? '修改寒暑假期学期' : '新增寒暑假期学期' }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">
					<a-form-item label="名称"><a-input v-decorator="['Name', { rules: [{ required: true, message: '请输入名称' }] }]" /></a-form-item>
					<a-form-item class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">{{ !text.ID ? '确认添加' : '确认修改' }}</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-item>
				</a-form>
			</div> 
		</div>
	</div>
</template>

<script>
import moment from 'moment';
import { ManagePracticeSessionTheme } from '@/api/follow';
export default {
	props: {
		text: Object
	},
	watch: {
		text: function(text) {
			if (!text.ID) {
				this.currentID = ''
			} else {
				this.currentID = text.ID;
				setTimeout(()=> {
					this.form.setFieldsValue({
						Name: text.Name,
					});
				}, 100);
			}
		}
	},
	data() {
		return {
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			currentID: '',
		};
	},
	created() {},
	methods: {
		moment,
		closeFunction(data) {
			this.form.resetFields();
			this.$emit('closeFun', data);
		},
		handleSubmit(e) {
			this.form.validateFields(async (err, values) => {
				if (!err) {
					let data = {};
					data = values
					data.SessionID = this.$route.query.ID
					let res = {};
					if (!this.currentID) {
						res = await ManagePracticeSessionTheme('DoAdd',data);
					} else {
						data.id = this.currentID;
						res = await ManagePracticeSessionTheme('DoUpdate',data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction('1');
					} else {
						this.$message.error(res.data.msg);
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
</style>
